package com.iwhalecloud.bss.kite.cucc.service.customerOrderInformation;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.iwhalecloud.bss.kite.cucc.common.callclient.HttpsCallClient;
import com.iwhalecloud.bss.kite.cucc.common.util.CommonUtil;
import com.ztesoft.bss.common.bo.OrgInfo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.iwhalecloud.bss.hsf.baseinf.service.InfExchangeService;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.JsonUtils;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.common.util.PageInfoUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.customerOrderInformation.ISerialNumberService;
import com.iwhalecloud.bss.kite.cucc.client.api.customerOrderInformation.UserCenterClient;
import com.iwhalecloud.bss.kite.cucc.client.api.inf.IInfServiceBus;
import com.iwhalecloud.bss.kite.cucc.client.api.reception.ICustReceptionService;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.Papr;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpMemberDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpMemberListByGrpReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpMemberListByMemReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpMemberListReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpUserDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryGrpUserListReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryMemDiscntInfoReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.QryTagInfos;
import com.iwhalecloud.bss.kite.cucc.client.dto.customerOrderInformation.UserDetailInfoReq;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.ProdInstQryDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.order.UserQueryDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.scene.CuccCustInfoDetailDTO;
import com.iwhalecloud.bss.kite.cucc.client.enumerate.UserDetailTagName;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.CustViewVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.Fee;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.FeeInfoVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.custview.HistoryFeeInfoVO;
import com.iwhalecloud.bss.kite.cucc.common.callclient.constant.CallClientEnum;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalCallClientEnum;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalInfConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.CuccOfferOriginalInfoCache;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.custview.evolve.CustViewCallable;
import com.iwhalecloud.bss.kite.cucc.service.custview.evolve.CustViewCallableBuilder;
import com.iwhalecloud.bss.kite.cucc.service.custview.evolve.task.GroupCustInfoTask;
import com.iwhalecloud.bss.kite.cucc.service.custview.evolve.task.MemberUserInfoTask;
import com.iwhalecloud.bss.kite.cucc.service.custview.evolve.task.ProductInfoTask;
import com.iwhalecloud.bss.kite.cucc.service.inf.InfServiceHelper;
import com.iwhalecloud.bss.kite.cucc.service.util.LocalTokenUtil;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;

import com.ztesoft.bss.common.bo.LoginInfo;
import com.ztesoft.bss.common.exception.BssException;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.DateUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import com.ztesoft.bss.order.base.consts.KeyValues;
import com.ztesoft.common.logger.api.ZLogger;
import com.ztesoft.common.logger.factory.ZLoggerFactory;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserCenterClientImpl implements UserCenterClient {

    private final ZLogger LOGGER = ZLoggerFactory.getLogger(this.getClass(), KeyConsts.LOG_MODULE);

    @Value("${interface.call.mode:hsf}")
    private String mode;

    @Override
    public Object userDetailInfo(UserDetailInfoReq userDetailInfoReq) {

        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        req.put("PROVINCE_CODE", userDetailInfoReq.getProvinceCode());

        req.put("STAFF_CODE", userDetailInfoReq.getStaffCode());
        if (KiteStringUtils.isNotBlank(userDetailInfoReq.getSerialNumber())) {
            req.put("SERIAL_NUMBER", userDetailInfoReq.getSerialNumber());
        }
        else if (KiteStringUtils.isNotBlank(userDetailInfoReq.getUserId())) {
            req.put("USER_ID", userDetailInfoReq.getUserId());
        }
        if (KiteStringUtils.isNotBlank(userDetailInfoReq.getUserSource())) {
            req.put("USER_SOURCE", userDetailInfoReq.getUserSource());
        }

        //国际工号，地市编码特殊处理 云账号方案针对省级工号不传地市编码，只查用户中心
        OrgInfo orgInfo=ContextUtil.getLoginInfo().getOrgInfo();
        if(!KiteObjectUtils.isEmpty(orgInfo)&&orgInfo.getOrgLevel()!=null&&orgInfo.getOrgLevel()==10){
//            req.put("EPARCHY_CODE", "499");
            if(KiteStringUtils.isNotBlank(userDetailInfoReq.getUserSource())){
                req.replace("USER_SOURCE", "2");
            }else {
                req.put("USER_SOURCE","2");
            }

        }else {
            req.put("EPARCHY_CODE", userDetailInfoReq.getEparchyCode());
        }
        List<Map<String, String>> qryTagInfoList = new ArrayList<>();
        List<QryTagInfos> qryTagInfos = userDetailInfoReq.getQryTagInfos();
        for (QryTagInfos qryTagInfo : qryTagInfos) {
            Map<String, String> map = new HashMap<>();
            map.put("TAG_NAME", qryTagInfo.getTagName());
            map.put("VALID_FLAG", qryTagInfo.getValidFlag());
            map.put("TRANSLATE_FLAG", qryTagInfo.getTranslateFlag());
            qryTagInfoList.add(map);
        }
        req.put("QRY_TAG_INFOS", qryTagInfoList);

        Map<String, String> tcpCount = new HashMap<>();
        tcpCount.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpCount.put("TRANS_ID", LocalTokenUtil.getTransId());
        req.put("TCP_CONT", tcpCount);

        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "json_bbssUserCenter_QryUserDetailServiceApi_qryUserDetailInfo");
        InfServiceHelper.adaptGray(request, req);

        //调接口查询用户详情信息
        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }

        if (KiteStringUtils.isNotEmpty(result)) {
            return JSON.parseObject(result, Map.class);
        }

        return null;
    }

    @Override
    public Object qryGrpMemberList(QryGrpMemberListReq qryGrpMemberListReq) {

        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        req.put("STAFF_CODE", qryGrpMemberListReq.getStaffCode());
        req.put("QRY_TYPE", qryGrpMemberListReq.getQryType());
        req.put("USER_ID", qryGrpMemberListReq.getUserId());
        req.put("START_ROW", qryGrpMemberListReq.getStartRow());
        req.put("END_ROW", qryGrpMemberListReq.getEndRow());

        //tcp_cont
        Map<String, String> tcpContMap = new HashMap<String, String>();
        tcpContMap.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpContMap.put("TRANS_ID", LocalTokenUtil.getTransId());
        req.put("TCP_CONT", tcpContMap);

        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "json_bbssUserCenter_SalBusaGrpMemberSerApi_QryGrpMemberList");
        InfServiceHelper.adaptGray(request, req);

        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }

        if (KiteStringUtils.isNotEmpty(result)) {
            return JSON.parseObject(result, Map.class);
        }

        return null;
    }

    @Override
    public PageInfo<QryGrpUserDTO> qryGrpUserList(QryGrpUserListReq qryGrpUserListReq) {
        String pageNum = qryGrpUserListReq.getPageNum();
        String pageSize = qryGrpUserListReq.getPageSize();
        pageNum = KiteStringUtils.isNotEmpty(pageNum) ? pageNum : "1";
        pageSize = KiteStringUtils.isNotEmpty(pageSize) ? pageSize : "10";
        Integer intpageNum = Integer.parseInt(pageNum);
        Integer intPageSize = Integer.parseInt(pageSize);
        Map<String, Object> request = dealGrpUserParams(qryGrpUserListReq, pageNum, pageSize);
        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }
        if (KiteStringUtils.isNotEmpty(result)) {
            Map resultMap = JSON.parseObject(result, Map.class);
            if (KiteMapUtils.isNotEmpty(resultMap)) {
                return dealGrpUserDTOPageInfo(intpageNum, intPageSize, resultMap);
            }
            else {
                return new PageInfo<QryGrpUserDTO>(new ArrayList<>());
            }
        }
        return new PageInfo<QryGrpUserDTO>(new ArrayList<>());
    }

    /**
     * 组装查询集团用户信息入参
     *
     * @param qryGrpUserListReq
     * @param pageNum
     * @param pageSize
     * @return
     */
    private Map<String, Object> dealGrpUserParams(QryGrpUserListReq qryGrpUserListReq, String pageNum,
        String pageSize) {
        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        Map<String, String> tcpCount = new HashMap<>();
        tcpCount.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpCount.put("TRANS_ID", LocalTokenUtil.getTransId());
        req.put("TCP_CONT", tcpCount);
        req.put("STAFF_CODE", qryGrpUserListReq.getStaffCode());
        req.put("CUST_ID", qryGrpUserListReq.getCustId());
        req.put("PROVINCE_CODE", qryGrpUserListReq.getProvinceCode());
        req.put("QRY_TYPE", "2");
        req.put("QRY_SOURCE", qryGrpUserListReq.getQrySource());
        req.put("SERVICE_TYPE_CODE", qryGrpUserListReq.getServiceTypeCode());
        req.put("SERIAL_NUMBER", qryGrpUserListReq.getSerialNumber());
        req.put("PAGE_NUM", pageNum);
        req.put("PAGE_SIZE", pageSize);
        List<Papr> paprList = qryGrpUserListReq.getPaprList();
        if (!KiteListUtils.isEmpty(paprList)) {
            List<Map<String, String>> papr = new ArrayList<>();
            paprList.forEach(item -> {
                Map<String, String> map = new HashMap<>();
                map.put("PARA_ID", item.getPaprId());
                map.put("PARA_VALUE", item.getPaprValue());
                papr.add(map);
            });
            req.put("PARA", papr);
        }
        req.put("USER_NAME", qryGrpUserListReq.getUserName());
        req.put("USER_DIFF_CODE", qryGrpUserListReq.getUserDiffCode());
        req.put("EPARCHY_CODE", qryGrpUserListReq.getEparchyCode());
        //国际业务云账号针对49工号，不传地市编码，只查用户中心
        OrgInfo orgInfo=ContextUtil.getLoginInfo().getOrgInfo();
        if(!KiteObjectUtils.isEmpty(orgInfo)&&orgInfo.getOrgLevel()!=null&&orgInfo.getOrgLevel()==10){
            req.remove("EPARCHY_CODE");
            req.replace("QRY_SOURCE","2");
        }
        req.put("CITY_CODE", qryGrpUserListReq.getCityCode());
        req.put("OPEN_STAFF_ID", qryGrpUserListReq.getOpenStaffId());
        req.put("USER_KIND", qryGrpUserListReq.getUserKind());
        req.put("GOODS_ID", qryGrpUserListReq.getGoodsId());
        req.put("SERVICE_ID", qryGrpUserListReq.getServiceId());
        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "json_bbssUserCenter_SalBusaGrpUserSerApi_qryGrpUserList");
        InfServiceHelper.adaptGray(request, req);
        return request;
    }

    /**
     * 处理qryGrpUserList返参节点
     *
     * @param intpageNum
     * @param intPageSize
     * @param resultMap
     * @return
     */
    private PageInfo<QryGrpUserDTO> dealGrpUserDTOPageInfo(Integer intpageNum, Integer intPageSize, Map resultMap) {
        Map<String, Object> unibssHeadMap = (Map<String, Object>) resultMap.get("UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(unibssHeadMap, "RESP_CODE"), LocalInfConsts.RESP_SUCCESS)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(unibssHeadMap, "RESP_DESC"));
        }

        Map<String, Object> rspUniBssBodyMap = (Map<String, Object>) resultMap.get("UNI_BSS_BODY");

        if (KiteMapUtils.isEmpty(rspUniBssBodyMap)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("返回报文缺少UNI_BSS_BODY节点");
        }
        Map<String, Object> rspMap = (Map<String, Object>) rspUniBssBodyMap.get("RSP");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(rspMap, "RSP_CODE"), "0000")) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(rspMap, "RSP_DESC"));
        }
        Map<String, Object> qryGrpUserListMap = (Map<String, Object>) rspMap.get("QRY_GRP_USER_LIST_RSP_BODY");
        Integer rowCount = KiteMapUtils.getInteger(qryGrpUserListMap, "ROW_COUNT");

        List<JSONObject> groupUserList = (List<JSONObject>) qryGrpUserListMap.get("GROUP_USER_LIST");

        List<QryGrpUserDTO> qryGrpUserDTOList = new ArrayList<QryGrpUserDTO>();

        if (KiteListUtils.isNotEmpty(groupUserList)) {
            groupUserList.forEach(item -> {
                QryGrpUserDTO prodInstQryDto = JSON.parseObject(item.toJSONString(), QryGrpUserDTO.class);
                //开户时间处理
                String openDate = prodInstQryDto.getOpenDate();
                Date dOpenDate = DateUtil.strToDate(openDate);
                openDate = DateUtil.format(dOpenDate);
                prodInstQryDto.setOpenDate(openDate);
                if (KiteStringUtils.isNotEmpty(prodInstQryDto.getGoodsId())) {
                    Map<String, Object> goodsInfoMap = CuccOfferOriginalInfoCache.get(prodInstQryDto.getGoodsId());
                    prodInstQryDto.setGoodsName(KiteMapUtils.getString(goodsInfoMap, "goodsName"));
                }
                prodInstQryDto.setUserLocationName(
                    LocalAttrHelper.getRegionName(prodInstQryDto.getProvinceCode()) + "-" + LocalAttrHelper
                        .getRegionName(prodInstQryDto.getEparchyCode()));
                qryGrpUserDTOList.add(prodInstQryDto);
            });
        }
        if (!Objects.nonNull(rowCount)) {
            rowCount = qryGrpUserDTOList.size();
        }
        //处理分页信息
        PageInfo<QryGrpUserDTO> resultPageInfo = new PageInfo<QryGrpUserDTO>();
        resultPageInfo.setList(qryGrpUserDTOList);
        resultPageInfo.setPageNum(intpageNum);
        resultPageInfo.setPageSize(intPageSize);
        resultPageInfo.setTotal(rowCount);
        int pages = rowCount / intPageSize;
        if (rowCount % intPageSize != 0) {
            pages++;
        }
        resultPageInfo.setPages(pages);
        return resultPageInfo;
    }

    /**
     * 处理qryGrpMember返参节点
     *
     * @param intpageNum
     * @param intPageSize
     * @param resultMap
     * @return
     */
    private PageInfo<QryGrpMemberDTO> dealGrpMemberDTOPageInfo(Integer intpageNum, Integer intPageSize, Map resultMap,
        QryGrpMemberListByGrpReq qryGrpMemberListByGrpReq) {
        Map<String, Object> unibssHeadMap = (Map<String, Object>) resultMap.get("UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(unibssHeadMap, "RESP_CODE"), LocalInfConsts.RESP_SUCCESS)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(unibssHeadMap, "RESP_DESC"));
        }
        Map<String, Object> rspUniBssBodyMap = (Map<String, Object>) resultMap.get("UNI_BSS_BODY");
        if (KiteMapUtils.isEmpty(rspUniBssBodyMap)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("返回报文缺少UNI_BSS_BODY节点");
        }
        Map<String, Object> rspMap = (Map<String, Object>) rspUniBssBodyMap.get("RSP");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(rspMap, "RESULT_CODE"), "0000")) {
            return new PageInfo<>();
            //            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(rspMap, "RESULT_MSG"));
        }
        Map<String, Object> resultObjectMap = (Map<String, Object>) rspMap.get("RESULT_OBJECT");
        Integer rowCount = KiteMapUtils.getInteger(resultObjectMap, "ROW_COUNT");
        if (KiteMapUtils.isEmpty(resultObjectMap)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(rspMap, "RESULT_MSG"));
        }
        Map<String, Object> groupMemberListMap = (Map<String, Object>) resultObjectMap.get("GROUP_MEMBERLIST");
        List<JSONObject> groupMemberList = (List<JSONObject>) groupMemberListMap.get("GROUP_MEMBERLISTS");
        List<QryGrpMemberDTO> grpMemberDTOList = new ArrayList<QryGrpMemberDTO>();
        if (KiteListUtils.isNotEmpty(groupMemberList)) {
            groupMemberList.forEach(item -> {
                QryGrpMemberDTO grpMemberDto = JSON.parseObject(item.toJSONString(), QryGrpMemberDTO.class);
                //成员生效时间处理
                String startDate = grpMemberDto.getStartDate();
                Date dstartDate = DateUtil.strToDate(startDate);
                startDate = DateUtil.format(dstartDate);
                grpMemberDto.setStartDate(startDate);
                //成员失效时间处理
                String endDate = grpMemberDto.getEndDate();
                Date dendDate = DateUtil.strToDate(endDate);
                endDate = DateUtil.format(dendDate);
                grpMemberDto.setEndDate(endDate);
                if (KiteStringUtils.isNotEmpty(grpMemberDto.getMemCustId()) && KiteStringUtils
                    .isNotEmpty(grpMemberDto.getMemSerialNumber())) {
                    ProdInstQryDTO prodInstQryDTO = getProdInstQryDTO(grpMemberDto.getMemCustId(),
                        grpMemberDto.getMemSerialNumber(), grpMemberDto.getMemProvinceCode(),
                        grpMemberDto.getMemEparchyCode());
                    grpMemberDto.setMemUserState(
                        KiteObjectUtils.isEmpty(prodInstQryDTO) ? "" : prodInstQryDTO.getUser_state_name());
                    grpMemberDto.setMemUserStateNo(
                        KiteObjectUtils.isEmpty(prodInstQryDTO) ? "" : prodInstQryDTO.getUser_state());
                }

                List<String> regionCodes = new ArrayList<>();
                if (KiteStringUtils.isNotEmpty(grpMemberDto.getMemProvinceCode())) {
                    regionCodes.add(grpMemberDto.getMemProvinceCode());
                }
                if (KiteStringUtils.isNotEmpty(grpMemberDto.getMemEparchyCode())) {
                    regionCodes.add(grpMemberDto.getMemEparchyCode());
                }
                if (KiteStringUtils.isNotEmpty(grpMemberDto.getMemCityCode())) {
                    regionCodes.add(grpMemberDto.getMemCityCode());
                }
                grpMemberDto.setMemEparchyName(LocalAttrHelper.getRegionNames(regionCodes, SymbolConsts.HYPHEN));

                grpMemberDTOList.add(grpMemberDto);
            });
        }
        if (!Objects.nonNull(rowCount)) {
            rowCount = grpMemberDTOList.size();
        }
        //处理分页信息
        PageInfo<QryGrpMemberDTO> resultPageInfo = new PageInfo<QryGrpMemberDTO>();
        resultPageInfo.setList(grpMemberDTOList);
        resultPageInfo.setPageNum(intpageNum);
        resultPageInfo.setPageSize(intPageSize);
        resultPageInfo.setTotal(rowCount);
        int pages = rowCount / intPageSize;
        if (rowCount % intPageSize != 0) {
            pages++;
        }
        resultPageInfo.setPages(pages);
        return resultPageInfo;
    }

    private ProdInstQryDTO getProdInstQryDTO(String custId, String serialNumberVal, String provinceCode,
        String eparchyCode) {
        IInfServiceBus infServiceBus = SpringUtil.getBean(IInfServiceBus.class);
        ProdInstQryDTO prodInstQryDTO = null;
        try {
            Map<String, String> map = new HashMap<>(5);
            map.put("custId", custId);
            map.put("accNum", serialNumberVal);
            map.put("eparchyCode", eparchyCode);
            map.put("provinceCode", provinceCode);
            UserQueryDTO userQueryDTO = infServiceBus.queryUserList(map);
            if (Objects.nonNull(userQueryDTO)) {
                List<ProdInstQryDTO> userList = userQueryDTO.getUserList().getList();
                if (KiteListUtils.isNotEmpty(userList)) {
                    prodInstQryDTO = userList.get(0);
                }
            }
        }
        catch (Exception e) {
            LOGGER.error(ErrorConsts.SYSTEM_ERROR.getErrorCode(), e, e.getMessage());
        }
        return prodInstQryDTO;
    }

    @Override
    public Object qryMemDiscntInfo(QryMemDiscntInfoReq qryMemDiscntInfoReq) {

        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        req.put("USER_IDA", qryMemDiscntInfoReq.getUserIda());
        req.put("MEMBER_USER_ID", qryMemDiscntInfoReq.getMemberUserId());
        req.put("STATE_FLAG", qryMemDiscntInfoReq.getStateFlag());
        req.put("STAFF_ID", qryMemDiscntInfoReq.getStaffId());

        //tcp_cont
        Map<String, String> tcpContMap = new HashMap<String, String>();
        tcpContMap.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpContMap.put("TRANS_ID", LocalTokenUtil.getTransId());
        req.put("TCP_CONT", tcpContMap);

        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "json_GEuserCenter_UserDiscntServiceApi_qryMemDiscntInfo");
        InfServiceHelper.adaptGray(request, req);

        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }

        if (KiteStringUtils.isNotEmpty(result)) {
            return JSON.parseObject(result, Map.class);
        }

        return null;
    }

    @Override
    public PageInfo<QryGrpMemberDTO> qryGrpMemberListByGrp(QryGrpMemberListByGrpReq qryGrpMemberListByGrpReq) {
        String pageNum = KiteStringUtils.valueOf(qryGrpMemberListByGrpReq.getCurPage());
        String pageSize = KiteStringUtils.valueOf(qryGrpMemberListByGrpReq.getPageSize());
        pageNum = KiteStringUtils.isNotEmpty(pageNum) ? pageNum : "1";
        pageSize = KiteStringUtils.isNotEmpty(pageSize) ? pageSize : "10";
        Integer intpageNum = Integer.parseInt(pageNum);
        Integer intPageSize = Integer.parseInt(pageSize);
        Map<String, Object> request = dealGrpMemberListInParams(qryGrpMemberListByGrpReq);
        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }
        if (KiteStringUtils.isNotEmpty(result)) {
            Map resultMap = JSON.parseObject(result, Map.class);
            if (KiteMapUtils.isNotEmpty(resultMap)) {
                return dealGrpMemberDTOPageInfo(intpageNum, intPageSize, resultMap, qryGrpMemberListByGrpReq);
            }
            else {
                return new PageInfo<QryGrpMemberDTO>(new ArrayList<>());
            }
        }
        return new PageInfo<QryGrpMemberDTO>(new ArrayList<>());
    }

    private Map<String, Object> dealGrpMemberListInParams(QryGrpMemberListByGrpReq qryGrpMemberListByGrpReq) {
        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        if (KiteStringUtils.isNotEmpty(qryGrpMemberListByGrpReq.getPrimaryUserId())) {
            req.put("PRIMARY_USER_ID", Long.parseLong(qryGrpMemberListByGrpReq.getPrimaryUserId()));
        }
        req.put("PRIMARY_SERIAL_NUMBER", qryGrpMemberListByGrpReq.getPrimarySerialNumber());
        req.put("RELATION_TYPE_CODE", "");
        req.put("PRIMARY_EPARCHY_CODE", qryGrpMemberListByGrpReq.getPrimaryEparchyCode());
        req.put("PRIMARY_PROVINCE_CODE", qryGrpMemberListByGrpReq.getPrimaryProvinceCode());
        req.put("FINISH_STATE", LocalKeyConsts.GROUP_RELATION_FINISH_STATE_1);
        req.put("QUERY_OLD_SYSTEM", qryGrpMemberListByGrpReq.getQueryOldSystem());
        req.put("CUR_PAGE", qryGrpMemberListByGrpReq.getCurPage());
        req.put("PAGE_SIZE", qryGrpMemberListByGrpReq.getPageSize());

        Map<String, Object> tcpCont = new HashMap<>();
        tcpCont.put("APP_KEY", LocalInfConsts.LOGIN_APP_ID);
        tcpCont.put("TRANS_ID", "");
        req.put("TCP_CONT", tcpCont);

        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "json_GEuserCenter_SalBusaGrpMemberSerApi_qryGrpMemberListByGrp");
        InfServiceHelper.adaptGray(request, req);
        return request;
    }

    @Override
    public PageInfo<QryGrpUserDTO> qryGrpMemberListByMem(QryGrpMemberListByMemReq qryGrpMemberListByMemReq) {
        String pageNum = KiteStringUtils.valueOf(qryGrpMemberListByMemReq.getCurPage());
        String pageSize = KiteStringUtils.valueOf(qryGrpMemberListByMemReq.getPageSize());
        pageNum = KiteStringUtils.isNotEmpty(pageNum) ? pageNum : "1";
        pageSize = KiteStringUtils.isNotEmpty(pageSize) ? pageSize : "10";
        Integer intpageNum = Integer.parseInt(pageNum);
        Integer intPageSize = Integer.parseInt(pageSize);
        Map<String, Object> request = dealGrpMemberInParams(qryGrpMemberListByMemReq);
        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }
        if (KiteStringUtils.isNotEmpty(result)) {
            Map resultMap = JSON.parseObject(result, Map.class);
            if (KiteMapUtils.isNotEmpty(resultMap)) {
                return dealGrpMemberOutParams(intpageNum, intPageSize, resultMap);
            }
            else {
                return new PageInfo<QryGrpUserDTO>(new ArrayList<>());
            }
        }
        return new PageInfo<QryGrpUserDTO>(new ArrayList<>());
    }

    /**
     * 处理qryGrpMember返参节点
     *
     * @param intpageNum
     * @param intPageSize
     * @param resultMap
     * @return
     */
    private PageInfo<QryGrpUserDTO> dealGrpMemberOutParams(Integer intpageNum, Integer intPageSize, Map resultMap) {
        Map<String, Object> unibssHeadMap = (Map<String, Object>) resultMap.get("UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(unibssHeadMap, "RESP_CODE"), LocalInfConsts.RESP_SUCCESS)) {
            return new PageInfo<QryGrpUserDTO>();
        }
        Map<String, Object> rspUniBssBodyMap = (Map<String, Object>) resultMap.get("UNI_BSS_BODY");
        if (KiteMapUtils.isEmpty(rspUniBssBodyMap)) {
            return new PageInfo<QryGrpUserDTO>();
        }
        Map<String, Object> rspMap = (Map<String, Object>) rspUniBssBodyMap.get("RSP");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(rspMap, "RESULT_CODE"), "0000")) {
            return new PageInfo<QryGrpUserDTO>();
        }
        Map<String, Object> resultObjectMap = (Map<String, Object>) rspMap.get("RESULT_OBJECT");
        Integer rowCount = KiteMapUtils.getInteger(resultObjectMap, "ROW_COUNT");
        if (KiteMapUtils.isEmpty(resultObjectMap)) {
            return new PageInfo<QryGrpUserDTO>();
        }
        Map<String, Object> groupMemberListMap = (Map<String, Object>) resultObjectMap.get("GROUP_MEMBERLIST");
        List<JSONObject> groupMemberList = (List<JSONObject>) groupMemberListMap.get("GROUP_MEMBERLISTS");
        List<QryGrpUserDTO> grpMemberDTOList = new ArrayList<QryGrpUserDTO>();
        if (KiteListUtils.isNotEmpty(groupMemberList)) {
            groupMemberList.forEach(item -> {
                QryGrpUserDTO qryGrpUserDTO = new QryGrpUserDTO();
                qryGrpUserDTO.setProvinceCode(KiteMapUtils.getString(item, "PRIMARY_PROVINCE_CODE")); //集团用户归属省份
                qryGrpUserDTO.setEparchyCode(KiteMapUtils.getString(item, "PRIMARY_EPARCHY_CODE")); //集团用户归属地市
                qryGrpUserDTO.setCityCode(KiteMapUtils.getString(item, "PRIMARY_EPARCHY_CODE")); //集团用户归属地市
                qryGrpUserDTO.setSerialNumber(KiteMapUtils.getString(item, "PRIMARY_SERIAL_NUMBER")); //集团业务号码
                qryGrpUserDTO.setUserId(KiteMapUtils.getString(item, "PRIMARY_USER_ID")); //集团用户标识
                qryGrpUserDTO.setUserName(KiteMapUtils.getString(item, "MEM_USER_NAME")); //集团用户名称
                qryGrpUserDTO.setRelationTypeCode(KiteMapUtils.getString(item, "RELATION_TYPE_CODE"));
                qryGrpUserDTO.setUserLocationName(
                    LocalAttrHelper.getRegionName(qryGrpUserDTO.getProvinceCode()) + "-" + LocalAttrHelper
                        .getRegionName(qryGrpUserDTO.getEparchyCode())); //集团用户归属地
                String memCustId = KiteMapUtils.getString(item, "MEM_CUST_ID");
                if (KiteStringUtils.isNotEmpty(memCustId) && KiteStringUtils.isNotEmpty(qryGrpUserDTO.getSerialNumber())
                    && KiteStringUtils.isNotEmpty(qryGrpUserDTO.getProvinceCode()) && KiteStringUtils
                    .isNotEmpty(qryGrpUserDTO.getEparchyCode())) {
                    ProdInstQryDTO prodInstQryDTO = getProdInstQryDTO(memCustId, qryGrpUserDTO.getSerialNumber(),
                        qryGrpUserDTO.getProvinceCode(), qryGrpUserDTO.getEparchyCode());
                    qryGrpUserDTO.setUserStateName(
                        KiteObjectUtils.isEmpty(prodInstQryDTO) ? "" : prodInstQryDTO.getUser_state_name());
                    qryGrpUserDTO
                        .setUserState(KiteObjectUtils.isEmpty(prodInstQryDTO) ? "" : prodInstQryDTO.getUser_state());
                    qryGrpUserDTO
                        .setGoodsName(KiteObjectUtils.isEmpty(prodInstQryDTO) ? "" : prodInstQryDTO.getGoods_name());
                }
                qryGrpUserDTO.setGroupDesc(""); //TODO
                qryGrpUserDTO.setRelationTypeName(KiteMapUtils.getString(item, "RELATION_TYPE_NAME"));
                String openDate = KiteMapUtils.getString(item, "START_DATE");
                Date dOpenDate = DateUtil.strToDate(openDate);
                openDate = DateUtil.format(dOpenDate);
                qryGrpUserDTO.setOpenDate(openDate);
                grpMemberDTOList.add(qryGrpUserDTO);
            });
        }
        if (!Objects.nonNull(rowCount)) {
            rowCount = grpMemberDTOList.size();
        }
        //处理分页信息
        PageInfo<QryGrpUserDTO> resultPageInfo = new PageInfo<QryGrpUserDTO>();
        resultPageInfo.setList(grpMemberDTOList);
        resultPageInfo.setPageNum(intpageNum);
        resultPageInfo.setPageSize(intPageSize);
        resultPageInfo.setTotal(rowCount);
        int pages = rowCount / intPageSize;
        if (rowCount % intPageSize != 0) {
            pages++;
        }
        resultPageInfo.setPages(pages);
        return resultPageInfo;
    }

    private Map<String, Object> dealGrpMemberInParams(QryGrpMemberListByMemReq qryGrpMemberListByMemReq) {
        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        if (KiteStringUtils.isNotEmpty(qryGrpMemberListByMemReq.getMemUserId())) {
            req.put("MEM_USER_ID", Long.parseLong(qryGrpMemberListByMemReq.getMemUserId()));
        }
        req.put("MEM_SERIAL_NUMBERS", qryGrpMemberListByMemReq.getMemSerialNumbers());
        req.put("MEM_SERIAL_NUMBER", qryGrpMemberListByMemReq.getMemSerialNumber());
        req.put("RELATION_TYPE_CODE", qryGrpMemberListByMemReq.getRelationTypeCode());
        req.put("MEM_EPARCHY_CODE", qryGrpMemberListByMemReq.getMemEparchyCode());
        req.put("MEM_PROVINCE_CODE", qryGrpMemberListByMemReq.getMemProvinceCode());
        req.put("FINISH_STATE", qryGrpMemberListByMemReq.getFinishState());
        req.put("QUERY_OLD_SYSTEM", qryGrpMemberListByMemReq.getQueryOldSystem());
        req.put("CUR_PAGE", qryGrpMemberListByMemReq.getCurPage());
        req.put("PAGE_SIZE", qryGrpMemberListByMemReq.getPageSize());

        //tcp_cont
        Map<String, String> tcpContMap = new HashMap<String, String>();
        tcpContMap.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpContMap.put("TRANS_ID", LocalTokenUtil.getTransId());
        req.put("TCP_CONT", tcpContMap);

        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "json_GEuserCenter_SalBusaGrpMemberSerApi_qryGrpMemberListByMem");
        InfServiceHelper.adaptGray(request, req);
        return request;
    }

    /**
     * 查询集团用户详情信息
     *
     * @param memSerialNumber
     * @return
     */
    @Override
    public CustViewVO qryGroupUserDetails(String memSerialNumber, String userState) {
        boolean isInvalid = KiteStringUtils.equals(userState, "40");
        CustViewVO custViewVO = new CustViewVO();
        KitePosDTO kitePosDTO = null;
        Map<String, Object> userDetail = null;
        //try {
        if (KiteStringUtils.isNotEmpty(memSerialNumber)) {
            try {
                Map<String, Object> orderInfo = this.getChangeOriginOrder(null, null, memSerialNumber, isInvalid);
                kitePosDTO = JSONObject.toJavaObject(JSON.parseObject(JSON.toJSONString(orderInfo)), KitePosDTO.class);
            }
            catch (BssException e) {
                ErrorConsts.INF_SALES_HANDLE_EXCEPTION.throwOut("业务号码" + memSerialNumber + "没有落户用户中心，不支持查询详情");
            }
        }
        // FIXME: 工号相关信息不一定是当前登录工号信息，等用户中心接口落地了应该做出修改
        String staffCode = ContextUtil.getLoginInfo().getStaffInfo().getStaffCode();
        String eparchyCode = ContextUtil.getLoginInfo().getUserInfo().getPostLanId();
        String provinceCode = ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr();
        Map<String, Object> inMap = new HashMap<>();
        inMap.put("accNum", memSerialNumber);
        inMap.put("staffCode", staffCode);
        inMap.put("eparchyCode", eparchyCode);
        inMap.put("provinceCode", provinceCode);
        userDetail = this.queryUserDetail(inMap, Lists
                .newArrayList(UserDetailTagName.USER, UserDetailTagName.USER_ITEM, UserDetailTagName.PAYRELATION,
                    UserDetailTagName.USER_DISCNT, UserDetailTagName.USER_DISCNT_ITEM, UserDetailTagName.USER_CONTRACT,
                    UserDetailTagName.USER_AGNET, UserDetailTagName.USER_DEVELOP, UserDetailTagName.USER_GOODS), isInvalid,
            "");
        if (KiteObjectUtils.isEmpty(userDetail)) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut("获取集团用户详情信息失败", "获取集团用户详情信息失败");
        }
        /*}
        catch (BeansException e) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut(e, "获取集团用户详情信息失败");
        }*/
        /*List<CustViewBaseTask> tasks = Lists
            .newArrayList(new GetGroupCustInfoTask(new Object[] {kitePosDTO, custViewVO, "1"}),
                new GetMemberUserInfoTask(new Object[] {userDetail, custViewVO, kitePosDTO}),
                new GetProductInfoTask(new Object[] {kitePosDTO, custViewVO}));*/

        List<CustViewCallable> custViewCallables = getCustViewCallables(custViewVO, kitePosDTO, userDetail);
        LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>执行任务开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        long start1 = System.currentTimeMillis();
        ExecutorService executorService = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1,
            Runtime.getRuntime().availableProcessors() + 1, 2000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(10),
            new ThreadFactoryBuilder().setNameFormat("groupMemberDetail-view-pool-%d").build());
        try {
            //            executorService.invokeAll(tasks);
            executorService.invokeAll(custViewCallables);
        }
        catch (InterruptedException e) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut(e, "集团用户订购信息查询失败");
        }
        finally {
            executorService.shutdown();
        }
        long end1 = System.currentTimeMillis();
        LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>执行任务结束>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        LOGGER.info("总耗时" + (end1 - start1) + "毫秒");
        return custViewVO;
    }

    private List<CustViewCallable> getCustViewCallables(CustViewVO custViewVO, KitePosDTO kitePosDTO,
        Map<String, Object> userDetail) {
        return Lists.newArrayList(new CustViewCallableBuilder().setCustViewTask(new GroupCustInfoTask())
                .setArgs(new Object[] {kitePosDTO, custViewVO, "1"}).withSession().build(),
            new CustViewCallableBuilder().setCustViewTask(new MemberUserInfoTask())
                .setArgs(new Object[] {userDetail, custViewVO, kitePosDTO}).withSession().build(),
            new CustViewCallableBuilder().setCustViewTask(new ProductInfoTask())
                .setArgs(new Object[] {kitePosDTO, custViewVO}).withSession().build());
    }

    /**
     * 查询用户详情
     *
     * @param inMap
     * @param userDetailTagNames TAG_NAME 详情见{@link UserDetailTagName}
     * @return
     */
    public Map<String, Object> queryUserDetail(Map<String, Object> inMap, List<UserDetailTagName> userDetailTagNames,
        boolean isInvalid, String isGroup) {
        if (KiteListUtils.isEmpty(userDetailTagNames)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("TAG_NAME不可为空");
        }
        String provinceCode = KiteMapUtils.getString(inMap, "provinceCode");
        String eparchyCode = KiteMapUtils.getString(inMap, "eparchyCode");
        String staffCode = (String) ContextUtil.getLoginInfo().getUserInfo().getExtParams().get("account");
        String accNum = KiteMapUtils.getString(inMap, "accNum");
        String userId = KiteMapUtils.getString(inMap, "userId");

        Map<String, Object> uniBssBodyMap = new HashMap<String, Object>();
        Map<String, Object> reqMap = new HashMap<String, Object>();
        //tcp_cont
        Map<String, String> tcpContMap = new HashMap<String, String>();
        tcpContMap.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpContMap.put("TRANS_ID", LocalTokenUtil.getTransId());
        reqMap.put("TCP_CONT", tcpContMap);

        // 员工工号（适配老销售）只查用户中心可不传递
        reqMap.put("STAFF_CODE", staffCode);
        // 服务号码（业务号码、用户标识二选一必填）
        reqMap.put("SERIAL_NUMBER", accNum);
        // 用户标识（业务号码、用户标识二选一必填）
        reqMap.put("USER_ID", userId);
        if (KiteStringUtils.equals("T", isGroup)) {
            // 省份编码(适配老销售)只查用户中心可不传递
            reqMap.put("PROVINCE_CODE", provinceCode);
            // 地市编码(适配老销售)只查用户中心可不传递，只查用户中心
            //国际工号，地市编码特殊处理
//            if(KiteStringUtils.isNotEmpty(provinceCode)&&provinceCode.startsWith("49")){
//                reqMap.put("EPARCHY_CODE", "499");
//            }else {
//                reqMap.put("EPARCHY_CODE", eparchyCode);
//            }
            // 只查询用户中心
            reqMap.put("USER_SOURCE", "1");
        }
        else {
            // 只查询用户中心
            reqMap.put("USER_SOURCE", "2");
        }

        //云业务受理针对省级工号
        OrgInfo orgInfo=ContextUtil.getLoginInfo().getOrgInfo();
        if(!KiteObjectUtils.isEmpty(orgInfo)&&orgInfo.getOrgLevel()!=null&&orgInfo.getOrgLevel()==10){
            reqMap.replace("USER_SOURCE", "2");
        }
        List<Map<String, String>> qryTagInfoList = new ArrayList<>();
        for (UserDetailTagName userDetailTagName : userDetailTagNames) {
            Map<String, String> qryTagInfo = new HashMap<>();
            qryTagInfo.put("TRANSLATE_FLAG", "1");
            qryTagInfo.put("VALID_FLAG", "1");
            qryTagInfo.put("TAG_NAME", userDetailTagName.name());
            if (KiteStringUtils.equalsAny(userDetailTagName.name(), UserDetailTagName.USER.name(),
                UserDetailTagName.USER_DISCNT.name(), UserDetailTagName.USER_DISCNT_ITEM.name())) {
                qryTagInfo.put("VALID_FLAG", "0");
            }
            if (isInvalid) {
                qryTagInfo.put("VALID_FLAG", "0");
            }
            qryTagInfoList.add(qryTagInfo);
        }
        reqMap.put("QRY_TAG_INFOS", qryTagInfoList);
        uniBssBodyMap.put("REQ", reqMap);
        Map<String, Object> requestMap = LocalTokenUtil.getParamMap(uniBssBodyMap);
        requestMap.put("OP_CODE", "json_bbssUserCenter_QryUserDetailServiceApi_qryUserDetailInfo");
        InfServiceHelper.adaptGray(requestMap, reqMap);

        //调接口查询用户详情信息
        Map rsp;
        if (KiteStringUtils.isEqual(mode, "http")) {
            rsp = HttpsCallClient.postObjMap(LocalCallClientEnum.INF_COMMON_URL.getCenterCode(),
                LocalCallClientEnum.INF_COMMON_URL.getServiceCode(), requestMap, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            String resultStr = infExchangeService.exchange(new JSONObject(requestMap));
            rsp = JSON.parseObject(resultStr, Map.class);
        }

        Map<String, Object> uniBssHead = (Map<String, Object>) rsp.get("UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(LocalInfConsts.RESP_SUCCESS, KiteMapUtils.getString(uniBssHead, "RESP_CODE"))) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(uniBssHead, "RESP_DESC"));
        }
        Map<String, Object> rspUniBssBodyMap = (Map<String, Object>) rsp.get("UNI_BSS_BODY");
        if (KiteMapUtils.isEmpty(rspUniBssBodyMap)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("接口返回报文缺少UNI_BSS_BODY节点信息!");
        }

        Map<String, Object> rspMap = (Map<String, Object>) rspUniBssBodyMap.get("RSP");
        if (!KiteStringUtils.equals("0000", KiteMapUtils.getString(rspMap, "RESP_CODE"))) {
            if (KiteStringUtils.equals("8888", KiteMapUtils.getString(rspMap, "RESP_CODE"))) {
                return null;
            }
            //ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(rspMap, "RESP_DESC"));
        }
        return rspMap;
    }

    /**
     * 查询用户详情
     *
     * @param
     * @param userDetailTagNames TAG_NAME 详情见{@link UserDetailTagName}
     * @return
     */
    @Override
    public Map<String, Object> queryMemberUserDetail(boolean isInvalid, String primaryUserId, String memUserId, List<UserDetailTagName> userDetailTagNames) {
        if (KiteListUtils.isEmpty(userDetailTagNames)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("TAG_NAME不可为空");
        }

        Map<String, Object> uniBssBodyMap = new HashMap<String, Object>();
        Map<String, Object> reqMap = new HashMap<String, Object>();
        //tcp_cont
        Map<String, String> tcpContMap = new HashMap<String, String>();
        tcpContMap.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpContMap.put("TRANS_ID", LocalTokenUtil.getTransId());
        reqMap.put("TCP_CONT", tcpContMap);

        // 群组用户标识
        reqMap.put("PRIMARY_USER_ID", primaryUserId);
        // 成员用户标识
        reqMap.put("MEM_USER_ID", memUserId);

        List<Map<String, String>> qryTagInfoList = new ArrayList<>();
        for (UserDetailTagName userDetailTagName : userDetailTagNames) {
            Map<String, String> qryTagInfo = new HashMap<>();
            qryTagInfo.put("TRANSLATE_FLAG", "1");
            qryTagInfo.put("VALID_FLAG", "1");
            qryTagInfo.put("TAG_NAME", userDetailTagName.name());
            if (KiteStringUtils.equalsAny(userDetailTagName.name(), UserDetailTagName.USER.name(),
                UserDetailTagName.USER_DISCNT.name(), UserDetailTagName.USER_DISCNT_ITEM.name())) {
                qryTagInfo.put("VALID_FLAG", "0");
            }
            if (isInvalid) {
                qryTagInfo.put("VALID_FLAG", "0");
            }
            qryTagInfoList.add(qryTagInfo);
        }
        reqMap.put("QRY_TAG_INFOS", qryTagInfoList);
        uniBssBodyMap.put("REQ", reqMap);
        Map<String, Object> requestMap = LocalTokenUtil.getParamMap(uniBssBodyMap);
        requestMap.put("OP_CODE", "json_chinaUnicom_govEnterprise_userCenter_qryExternalUserDetailInfo");
        InfServiceHelper.adaptGray(requestMap, reqMap);

        //调接口查询用户详情信息
        Map rsp;
        if (KiteStringUtils.isEqual(mode, "http")) {
            rsp = HttpsCallClient.postObjMap(LocalCallClientEnum.INF_COMMON_URL.getCenterCode(),
                LocalCallClientEnum.INF_COMMON_URL.getServiceCode(), requestMap, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            String resultStr = infExchangeService.exchange(new JSONObject(requestMap));
            rsp = JSON.parseObject(resultStr, Map.class);
        }

        Map<String, Object> uniBssHead = (Map<String, Object>) rsp.get("UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(LocalInfConsts.RESP_SUCCESS, KiteMapUtils.getString(uniBssHead, "RESP_CODE"))) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(uniBssHead, "RESP_DESC"));
        }
        Map<String, Object> rspUniBssBodyMap = (Map<String, Object>) rsp.get("UNI_BSS_BODY");
        if (KiteMapUtils.isEmpty(rspUniBssBodyMap)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("接口返回报文缺少UNI_BSS_BODY节点信息!");
        }

        Map<String, Object> rspMap = (Map<String, Object>) rspUniBssBodyMap.get("RSP");
        if (!KiteStringUtils.equals("0000", KiteMapUtils.getString(rspMap, "RESP_CODE"))) {
            if (KiteStringUtils.equals("8888", KiteMapUtils.getString(rspMap, "RESP_CODE"))) {
                return null;
            }
        }
        return rspMap;
    }

    /***
     * 从集客获取变更信息
     * @param productId
     * @param custId
     * @param serialNumber
     * @return
     */
    public Map<String, Object> getChangeOriginOrder(String productId, String custId, String serialNumber,
        boolean isInvalid) {

        Map<String, Object> param = new HashMap<>();
        Map uniBssBody = new HashMap();
        Map requestReq = new HashMap();
        Map tcpCont = new HashMap();
        LoginInfo loginInfo = ContextUtil.getLoginInfo();
        List qryTagInfo = generateQryTagInfo(isInvalid);

        param.put("OP_CODE", "qryUserDetailInfo_erCiYeWu");
        param.put("UNI_BSS_BODY", uniBssBody);

        uniBssBody.put("REQ", requestReq);

        requestReq.put("TCP_CONT", tcpCont);
        requestReq.put("QRY_TAG_INFOS", qryTagInfo);

        requestReq.put("SERIAL_NUMBER", serialNumber);
        requestReq.put("STAFF_CODE", loginInfo.getStaffInfo().getStaffCode());
        //只查用户中心
        requestReq.put("USER_SOURCE", "2");
        requestReq.put("IS_SELECT_CONTRACT", "0");

        String trans_id = LocalTokenUtil.getDate_yyyyMMddHHmmssSSS() + LocalTokenUtil.randomNum(6);
        tcpCont.put("APP_KEY", "appId");
        tcpCont.put("TRANS_ID", trans_id);
        InfServiceHelper.adaptGray(param, requestReq);

        Map<String, Object> dataMap = new HashMap<>();

        Map result = new HashMap();
        DcPublic cfg = DcPublicCache.get("20112401", "modifySwitch");
        String flag = cfg.getCodea();
        if ("T".equals(flag)) {
            //测试阶段取配置报文返回,后续接口完善后删除
            String rsp = cfg.getCodeb();
            Map<String, Object> orderMap = JSON.parseObject(rsp, Map.class);
            dataMap = (Map<String, Object>) orderMap.get("data");
        }
        else {
            String resultStr;
            if (KiteStringUtils.isEqual(mode, "http")) {
                resultStr = HttpsCallClient.postStringWithObject(CallClientEnum.QRY_CHANGE_ORIGIN_ORDER, param, null);
            }
            else {
                InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
                resultStr = infExchangeService.exchange(new JSONObject(param));
            }
            if (KiteStringUtils.isEmpty(resultStr)) {
                ErrorConsts.INF_INVOKE_ERROR
                    .throwOut(LocalCallClientEnum.QRY_CHANGE_ORIGIN_ORDER.getServiceCode(), "获取变更单信息失败", "获取变更单信息失败");
            }
            result = JSON.parseObject(resultStr, Map.class);
            if (KiteMapUtils.isNotEmpty(result)) {
                String respDesc = KiteMapUtils.getString(result, "status");
                if (KiteStringUtils.isEqual("0", respDesc)) {
                    dataMap = (Map<String, Object>) result.get("data");
                }
                else {
                    ErrorConsts.INF_INVOKE_ERROR
                        .throwOut(LocalCallClientEnum.QRY_CHANGE_ORIGIN_ORDER.getServiceCode(), "获取变更单信息失败",
                            "获取变更单信息失败");
                }
            }
            else {
                ErrorConsts.INF_INVOKE_ERROR
                    .throwOut(LocalCallClientEnum.QRY_CHANGE_ORIGIN_ORDER.getServiceCode(), "获取变更单信息失败", "获取变更单信息失败");
            }
        }

        if (dataMap == null) {
            ErrorConsts.INF_INVOKE_ERROR
                .throwOut(LocalCallClientEnum.QRY_CHANGE_ORIGIN_ORDER.getServiceCode(), "获取变更单信息失败", "获取变更单信息失败");
        }
        return dataMap;
    }

    private List generateQryTagInfo(boolean isInvalid) {
        List tagInfoList = new ArrayList();
        String tagNames = DcPublicCache.getCodec("20112401", "modifySwitch");
        String[] keys = tagNames.split(",");
        for (int i = 0; i < keys.length; i++) {
            Map tagInfo = new HashMap();
            tagInfo.put("TRANSLATE_FLAG", "1");
            tagInfo.put("VALID_FLAG", "1");
            if (KiteStringUtils.equals(keys[i], "USER")) {
                tagInfo.put("VALID_FLAG", "0");
            }
            if (isInvalid) {
                tagInfo.put("VALID_FLAG", "0");
            }
            tagInfo.put("TAG_NAME", keys[i]);
            tagInfoList.add(tagInfo);
        }
        return tagInfoList;
    }

    @Override
    public CustViewVO qryMemberFeeInfo(QryGrpMemberDTO qryGrpMemberDTO) {
        CustViewVO custViewVO = new CustViewVO();
        Map<String, Object> grpUserDetailMapData = new HashMap<String, Object>();
        try {
            grpUserDetailMapData = dealMemberUserDetailInfoInParams(qryGrpMemberDTO);
            if (KiteMapUtils.isNotEmpty(grpUserDetailMapData)) {
                custViewVO = execute(grpUserDetailMapData);
            }
        }
        catch (BeansException e) {
            //            ErrorConsts.BUSI_COMMON_ERROR.throwOut(e, "获取集团用户详情信息失败");
        }
        return custViewVO;
    }

    @Override
    public List<Map<String, Object>> qryGroupUserInfoDetails(String sceneInstId, String memSerialNumber,
        String userState, String serviceTypeCode, String isGroup) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        boolean isInvalid = KiteStringUtils.equals(userState, "40");
        Map<String, Object> result = new HashMap<>();
        List<Map<String, Object>> resultList = new ArrayList<>();
        LoginInfo loginInfo = ContextUtil.getLoginInfo();
        String userId = ContextUtil.getUserId().toString();
        String staffCode = (String) loginInfo.getUserInfo().getExtParams().get("account");
        //String staffCode = loginInfo.getStaffInfo().getStaffCode();
        String eparchyCode = loginInfo.getUserInfo().getPostLanId();
        String provinceCode = loginInfo.getUserInfo().getPostProvinceNbr();

        Map<String, Object> inMap = new HashMap<>();
        inMap.put("accNum", memSerialNumber);
        //inMap.put("serviceTypeCode", serviceTypeCode); 对于政企支撑业务，电信类型选择错误但成员用户存在也可以加入，故这里不传电信类型
        inMap.put("staffCode", staffCode);
        inMap.put("eparchyCode", eparchyCode);
        inMap.put("provinceCode", provinceCode);
        inMap.put("cityCode", provinceCode);
        inMap.put("staffId", Long.toString(loginInfo.getStaffInfo().getStaffId()));
        // 成员加入的时候，需要判断一下集团是否有external_user_id，成员如果是归属政企的，也需要判断一下这个字段。
        // 最终群组关系是要同步给cb的，如果没有external_user_id，说明cb侧没有集团群组用户或者成员用户，给cb同步群组关系会报错
        Map<String, Object> userDetailToalInfo = this.queryUserDetailNew(inMap, Lists
            .newArrayList(UserDetailTagName.USER, UserDetailTagName.USER_ITEM, UserDetailTagName.PAYRELATION,
                UserDetailTagName.USER_DISCNT, UserDetailTagName.USER_DISCNT_ITEM, UserDetailTagName.USER_CONTRACT,
                UserDetailTagName.USER_AGNET, UserDetailTagName.USER_DEVELOP, UserDetailTagName.USER_GOODS,
                UserDetailTagName.USER_SERVICE, UserDetailTagName.USER_SERVICE_ITEM_GROUP,
                UserDetailTagName.USER_SERVICE_ITEM_GROUP_DETAIL));
        if (userDetailToalInfo != null && KiteStringUtils
            .equals("0000", KiteMapUtils.getString(userDetailToalInfo, "RESULT_CODE"))) {
            Map<String, Object> resultbjectOMap = (Map<String, Object>) userDetailToalInfo.get("RESULT_OBJECT");
            Map<String, Object> rspBodyMap = new HashMap<>();
            JSONArray userInfoArray = null;
            if (KiteMapUtils.isNotEmpty(resultbjectOMap) && KiteMapUtils
                .isNotEmpty((Map<String, Object>) resultbjectOMap.get("RSP_BODY"))) {
                rspBodyMap = (Map<String, Object>) resultbjectOMap.get("RSP_BODY");
                userInfoArray = (JSONArray) rspBodyMap.get("USER_INFO");
            }
            if (!KiteObjectUtils.isEmpty(userInfoArray)) {
                userInfoArray.forEach(userInfo -> {
                    JSONObject userInfoObject = (JSONObject) userInfo;
                    if (!KiteObjectUtils.isEmpty(userInfoObject)) {
                        JSONArray userInfosArray = (JSONArray) userInfoObject.get("USER_INFO_USER_INFO");
                        userInfosArray.forEach(userInfos -> {
                            JSONObject userInfosObject = (JSONObject) userInfos;
                            Iterator<String> it = userInfosObject.keySet().iterator();
                            while (it.hasNext()) {
                                String key = it.next();
                                result.put(key.toLowerCase(), KiteMapUtils.getString(userInfosObject, key));
                            }
                        });
                    }
                });
            }
            else {
                qryMemberByCbInterface(sceneInstId, memSerialNumber, serviceTypeCode, querySceneInstService, result,
                    resultList, userId, eparchyCode, provinceCode);
                if (KiteListUtils.isEmpty(resultList)) {
                    BssException.throwOut("无此用户资料信息", "无此用户资料信息", "无此用户资料信息");
                }

                // 成员退出，上面if的 集团用户查询服务，入参为成员业务号码时，查不到数据，走到else分支，导致提交用户中心反馈成员号码开始时间不对
                String business_number = querySceneInstService.getCommonAttrValue(sceneInstId, "business_number");
                IInfServiceBus infServiceBus = SpringUtil.getBean(IInfServiceBus.class);
                QryGrpMemberListByGrpReq qryGrpMemberListByGrpReq = new QryGrpMemberListByGrpReq();
                qryGrpMemberListByGrpReq.setPrimarySerialNumber(business_number);
                qryGrpMemberListByGrpReq.setMemSerialNumber(memSerialNumber);
                qryGrpMemberListByGrpReq.setPrimaryProvinceCode(provinceCode);
                qryGrpMemberListByGrpReq.setPrimaryEparchyCode(eparchyCode);
                qryGrpMemberListByGrpReq.setCurPage(1);
                qryGrpMemberListByGrpReq.setPageSize(1);
                // 调 群组查成员列表 接口，获取成员号码在用户中心的startDate
                Map<String, Object> groupMemberObj = infServiceBus.qryGrpMemberListByGrpNew(qryGrpMemberListByGrpReq);
                Map<String, Object> groupMemberMap = KiteMapUtils.getMap(groupMemberObj, "GROUP_MEMBERLIST");
                List<Map<String, Object>> groupMemberList = CommonUtil.getList(groupMemberMap, "GROUP_MEMBERLISTS");
                if(KiteListUtils.isNotEmpty(groupMemberList)) {
                    String startDate = KiteMapUtils.getString(groupMemberList.get(0), "START_DATE");
                    if(KiteStringUtils.isNotEmpty(startDate)) {
                        result.put("open_date", startDate);
                    }
                }

                return resultList;
            }
            if (KiteStringUtils.isEqual("99", KiteMapUtils.getString(result, "user_source"))) {
                result.put("user_source", "1");
            }
            result.put("service_type_code",
                Optional.ofNullable(AttrValueCache.get("20210304001")).orElse(Lists.newArrayList()).stream()
                    .filter(value -> KiteStringUtils.equals(value.getAttrValue(), serviceTypeCode)).findAny()
                    .map(AttrValue::getAttrValueName).orElse(null));

            result.put("primary_user_id", querySceneInstService.getCommonAttrValue(sceneInstId, "group_user_name"));
            result
                .put("primary_serial_number", querySceneInstService.getCommonAttrValue(sceneInstId, "business_number"));
            String custId = KiteMapUtils.getString(result, "cbss_cust_id");
            ICustReceptionService custReceptionService = SpringUtil.getBean(ICustReceptionService.class);
            CuccCustInfoDetailDTO cuccCustInfoDTO = custReceptionService.getCustomerInfoNew(custId);
            if (Objects.nonNull(cuccCustInfoDTO)) {
                result.put("licence_type",
                    Optional.ofNullable(AttrValueCache.get("2020022921000")).orElse(Lists.newArrayList()).stream()
                        .filter(
                            value -> KiteStringUtils.equals(value.getAttrValue(), cuccCustInfoDTO.getCertiTypeCode()))
                        .findAny().map(AttrValue::getAttrValueName).orElse(null));
                result.put("licence_number", cuccCustInfoDTO.getCertiCode());
                result.put("cust_name", cuccCustInfoDTO.getCustName());
            }
            resultList.add(result);
        }
        else {
            qryMemberByCbInterface(sceneInstId, memSerialNumber, serviceTypeCode, querySceneInstService, result,
                resultList, userId, eparchyCode, provinceCode);
        }

        if (KiteListUtils.isEmpty(resultList)) {
            BssException.throwOut("用户不存在，请检查电信类型是否正确", "用户不存在，请检查电信类型是否正确", "用户不存在，请检查电信类型是否正确");
        }
        return resultList;
    }

    private void qryMemberByCbInterface(String sceneInstId, String memSerialNumber, String serviceTypeCode,
        IQuerySceneInstService querySceneInstService, Map<String, Object> result, List<Map<String, Object>> resultList,
        String userId, String eparchyCode, String provinceCode) {
        // 调cb接口
        Map<String, String> inParams = new HashMap<>();
        inParams.put("serialNumber", memSerialNumber);
        inParams.put("serviceClassCode", serviceTypeCode);
        inParams.put("provinceCode", provinceCode);
        inParams.put("eparchyCode", eparchyCode);
        // 设置BBSS_INFO节点参数
        inParams.put("EPARCHY_CODE", eparchyCode);
        inParams.put("PROVINCE_CODE", provinceCode);
        inParams.put("OPER_ID", userId);
        inParams.put("CHANNEL_TYPE", "1000000");
        inParams.put("CHANNEL_ID", "9999999");
        inParams.put("ORIG_DOMAIN", "BBSS");
        IInfServiceBus infServiceBus = SpringUtil.getBean(IInfServiceBus.class);
        Map<String, Object> cbUserInfoMap = infServiceBus.queryGroupMemberUserInfo(inParams);
        if (KiteMapUtils.isNotEmpty(cbUserInfoMap)) {
            result.put("serial_number", memSerialNumber);
            result.put("open_date", KiteMapUtils.getString(cbUserInfoMap, "openDate"));
            result.put("user_name", KiteMapUtils.getString(cbUserInfoMap, "useName"));
            result.put("user_id", KiteMapUtils.getString(cbUserInfoMap, "provinceUserId"));
            result.put("user_source", "2");

            result.put("licence_type",
                Optional.ofNullable(AttrValueCache.get("2020022921000")).orElse(Lists.newArrayList()).stream()
                    .filter(value -> KiteStringUtils
                        .equals(value.getAttrValue(), (String) cbUserInfoMap.get("useCertType"))).findAny()
                    .map(AttrValue::getAttrValueName).orElse(null));
            result.put("licence_number", (String) cbUserInfoMap.get("useCert"));
            result.put("cust_name", (String) cbUserInfoMap.get("useName"));
            result.put("cbss_cust_id", (String) cbUserInfoMap.get("useProCustId"));
            result.put("service_type_code",
                Optional.ofNullable(AttrValueCache.getAttrValue("20210304001", serviceTypeCode))
                    .map(AttrValue::getAttrValueName).orElse(""));
            result.put("primary_user_id", querySceneInstService.getCommonAttrValue(sceneInstId, "group_user_name"));
            result.put("primary_serial_number",
                querySceneInstService.getCommonAttrValue(sceneInstId, "business_number"));
            resultList.add(result);
        }
    }

    @Override
    public String checkSerialNumber(String sceneInstId, String serialNumber, String memSerialNumber,
        List<Map<String, Object>> mapList) {
        UserCenterClient userCenterClient = SpringUtil.getBean(UserCenterClient.class);
        ISerialNumberService serialNumberService = SpringUtil.getBean(ISerialNumberService.class);
        String checkMsg = "";
        QryGrpMemberListByMemReq qryGrpMemberListByMemReq = new QryGrpMemberListByMemReq();
        qryGrpMemberListByMemReq.setMemSerialNumber(memSerialNumber);
        qryGrpMemberListByMemReq.setCurPage(Long.valueOf("1"));
        qryGrpMemberListByMemReq.setPageSize(Long.valueOf("10"));
        qryGrpMemberListByMemReq.setFinishState(LocalKeyConsts.GROUP_RELATION_FINISH_STATE_1);
        PageInfo<QryGrpUserDTO> qryGrpUserDTO = userCenterClient.qryGrpMemberListByMem(qryGrpMemberListByMemReq);
        if (qryGrpUserDTO.getTotal() > 0) {
            checkMsg = "成员业务号码：" + memSerialNumber + ",已加入归集集团，不允许再次加入";
        }
        if (KiteListUtils.isEmpty(mapList)) {
            checkMsg = "成员与集团归属不同省分，不允许加入";
        }
        String userDiffCode = getCode(mapList, "user_diff_code");
        if (KiteStringUtils.equals("28", userDiffCode)) {
            checkMsg = "填写的成员用户号码为归集集团业务号码，不允许加入";
        }
        String catagoryId = getCode(mapList, "goods_classify_id");
        //        checkMsg = checkPassageOrder(memSerialNumber, catagoryId);
        return checkMsg;
    }

    public String checkPassageOrder(String memSerialNumber, String catagoryId) {
        String checkMsg = "";
        ISerialNumberService serialNumberService = SpringUtil.getBean(ISerialNumberService.class);
        Map<String, String> checkReqMap = new HashMap<>(4);
        checkReqMap.put("SERIAL_NUMBER", memSerialNumber);
        checkReqMap.put("TYPE", "order");
        checkReqMap.put("GOODS_CATAGORY_ID", catagoryId);
        Map<String, Object> checkMap = serialNumberService.checkPassageOrder(checkReqMap);
        if (!KiteStringUtils.isEqual(KiteMapUtils.getString(checkMap, "code"), "00000")) {
            checkMsg = "校验业务号码是否有在途单接口失败：" + KiteMapUtils.getString(checkMap, "message");
        }
        if (KiteMapUtils.getBooleanValue(checkMap, "data", true)) {
            checkMsg = "业务号码：" + memSerialNumber + "，已经存在在途单，请核对后操作";
        }
        return checkMsg;
    }

    public String getCode(List<Map<String, Object>> mapList, String code) {
        Map<String, Object> map = mapList.get(0);
        String codeValue = KiteMapUtils.getString(map, code);
        return codeValue;
    }

    @Override
    public PageInfo<Map> qryGrpMemberListByCust(String sceneInstId, String custId, String memSerialNumber,
        String primaryUserId, String primaryUserName, String primarySerialNumber, String finishState, String curPage, String pageSize) {
        SpringUtil.getBean(IOperateSceneInstService.class).removeExtParameter(sceneInstId, "delGroupUserInfos");
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("CUST_ID", custId);
        paramMap.put("USER_DIFF_CODE", "28");
        paramMap.put("MEM_SERIAL_NUMBER", memSerialNumber);
        if (KiteStringUtils.isNotBlank(primaryUserId) && KiteStringUtils.isNum(primaryUserId)) {
            paramMap.put("PRIMARY_USER_ID", Long.valueOf(primaryUserId));
        }
        paramMap.put("PRIMARY_USER_NAME", primaryUserName);
        paramMap.put("PRIMARY_SERIAL_NUMBER", primarySerialNumber);
        if (KiteStringUtils.isBlank(curPage)) {
            curPage = "1";
        }
        paramMap.put("CUR_PAGE", Integer.valueOf(curPage));
        if (KiteStringUtils.isBlank(pageSize)) {
            pageSize = "10";
        }
        if (!KiteStringUtils.isEmpty(finishState)) {
            paramMap.put("FINISH_STATE", finishState);
        }
        paramMap.put("PAGE_SIZE", Integer.valueOf(pageSize));
        Map<String, Object> tcpCont = new HashMap<>();
        tcpCont.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpCont.put("TRANS_ID", LocalTokenUtil.getTransId());
        paramMap.put("TCP_CONT", tcpCont);
        Map<String, Object> req = new HashMap<>();
        req.put("REQ", paramMap);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY", req);
        request.put("OP_CODE", "json_GEuserCenter_SalBusaGrpMemberSerApi_qryGrpMemberListByCust");
        String result;
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }
        Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
        Map<String, Object> uniBssHead = KiteMapUtils.getValue(resultMap, "UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(uniBssHead, "RESP_CODE"), LocalInfConsts.RESP_SUCCESS)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(uniBssHead, "RESP_DESC"));
        }
        Map<String, Object> uniBssBody = KiteMapUtils.getValue(resultMap, "UNI_BSS_BODY");
        if (KiteMapUtils.isEmpty(uniBssBody)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("返回报文缺少UNI_BSS_BODY节点");
        }
        Map<String, Object> rspMap = KiteMapUtils.getValue(uniBssBody, "RSP");
        if (!KiteStringUtils.equals(KiteMapUtils.getString(rspMap, "RESULT_CODE"), "0000")) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut(KiteMapUtils.getString(rspMap, "RESULT_MSG"));
        }
        Map<String, Object> resultObject = KiteMapUtils.getValue(rspMap, "RESULT_OBJECT");
        Map<String, Object> memberlist = KiteMapUtils.getValue(resultObject, "GROUP_MEMBERLIST");
        List<Map> list = JsonUtils.parseArray(
            Optional.ofNullable(KiteMapUtils.getValue(memberlist, "GROUP_MEMBERLISTS")).orElse("").toString(),
            Map.class);
        List<Map> resultList = new ArrayList<>();
        list.stream().forEach(map -> {
            LocalDateTime now = LocalDateTime.now();
            String nowTime = now.format(DateTimeFormatter.ofPattern(KeyConsts.DATE_FORMAT_YYYYMMDDHHMMSS));
            String endDate = KiteMapUtils.getString(map, "END_DATE");
            if (Long.valueOf(endDate) > Long.valueOf(nowTime)) {
                resultList.add(map);
            }
        });
        // 部分返回值特殊处理
        dealGrpMemberListResult(resultList);
        Integer total = null;
        if (KiteListUtils.isNotEmpty(resultList)) {
            total = resultList.size();
        }
        else if (Objects.nonNull(KiteMapUtils.getValue(resultObject, "ROW_COUNT"))) {
            total = KiteMapUtils.getInteger(resultObject, "ROW_COUNT");
        }
        DcPublic dc = DcPublicCache.get("20210528001", "1");
        String swicth = dc.getCodea();
        //增加开关处理
        if (KiteStringUtils.isEqual(KeyValues.IFTRUE_T, swicth)) {
            for (Map map : resultList) {
                String checkMsg = checkPassageOrder(KiteMapUtils.getString(map, "MEM_SERIAL_NUMBER"), "");
                if (!KiteStringUtils.isEmpty(checkMsg)) {
                    map.put("isDisabled", "T");
                    map.put("checkMsg", checkMsg);
                }
            }
        }
        return PageInfoUtils.coverToPageTotal(resultList, Integer.valueOf(curPage), Integer.valueOf(pageSize), total);
    }

    private void dealGrpMemberListResult(List<Map> list) {
        if (KiteListUtils.isEmpty(list)) {
            return;
        }
        list.stream().forEach(map -> {
            // 归属地
            String provinceCode = KiteMapUtils.getString(map, "MEM_PROVINCE_CODE");
            String cityCode = KiteMapUtils.getString(map, "MEM_CITY_CODE");
            String eparchyCode = KiteMapUtils.getString(map, "MEM_EPARCHY_CODE");
            if (KiteStringUtils.isNotEmpty(provinceCode) && KiteStringUtils.isNotEmpty(cityCode)) {
                map.put("userLocationName", KiteStringUtils
                    .join(LocalAttrHelper.getRegionName(provinceCode), "-", LocalAttrHelper.getRegionName(cityCode),
                        "-", LocalAttrHelper.getRegionName(eparchyCode)));
            }
            // 用户群标签 0-集团；1-公众
            String userGrpTag = KiteMapUtils.getString(map, "MEM_USER_GRP_TAG");
            if (KiteStringUtils.equals(userGrpTag, "1")) {
                map.put("MEM_USER_GRP_TAG_NAME", "公众");
            }
            else if (KiteStringUtils.equals(userGrpTag, "0")) {
                map.put("MEM_USER_GRP_TAG_NAME", "集团");
            }
            // 归集标签 0-集团；1-公众
            String memRevTag = KiteMapUtils.getString(map, "MEM_REV_TAG");
            if (KiteStringUtils.equals(memRevTag, "1")) {
                map.put("MEM_REV_TAG_NAME", "公众");
            }
            else if (KiteStringUtils.equals(userGrpTag, "0")) {
                map.put("MEM_REV_TAG_NAME", "集团");
            }
            // 统一入网标签 0-统一入网；1-普通
            String inNetTag = KiteMapUtils.getString(map, "MEM_IN_NET_TAG");
            if (KiteStringUtils.equals(inNetTag, "1")) {
                map.put("MEM_IN_NET_TAG_NAME", "普通");
            }
            else if (KiteStringUtils.equals(inNetTag, "0")) {
                map.put("MEM_IN_NET_TAG_NAME", "统一入网");
            }
            if (KiteStringUtils.isNotEmpty(KiteMapUtils.getString(map, "MEM_SOURCE"))) {
                map.put("user_source", KiteMapUtils.getString(map, "MEM_SOURCE"));
            }
        });
    }

    private CustViewVO execute(Map<String, Object> grpUserDetailMapData) {
        CustViewVO custViewVO = new CustViewVO();
        FeeInfoVO feeInfoVO = new FeeInfoVO();
        HistoryFeeInfoVO hisFeeInfoVO = new HistoryFeeInfoVO();
        custViewVO.setFee(feeInfoVO);
        custViewVO.setHistoryFee(hisFeeInfoVO);
        List<Fee> resultfees = Lists.newArrayList();
        List<Fee> resultHisfees = Lists.newArrayList();
        if (KiteMapUtils.isNotEmpty(grpUserDetailMapData) && !KiteObjectUtils
            .isEmpty(grpUserDetailMapData.get("goods"))) {
            List<Map<String, Object>> goodsList = (List<Map<String, Object>>) grpUserDetailMapData.get("goods");
            goodsList.stream().forEach(goods -> {
                List<Map<String, Object>> feesList = (List<Map<String, Object>>) goods.get("fees");
                if (KiteListUtils.isNotEmpty(feesList)) {
                    for (Map<String, Object> feesMap : feesList) {
                        Fee fee = new Fee();
                        fee.setFeeCode(KiteMapUtils.getString(feesMap, "code"));
                        // 资费名称
                        fee.setFeeName(KiteMapUtils.getString(feesMap, "feeName"));
                        // 资费描述
                        fee.setFeeDesc(KiteMapUtils.getString(feesMap, "feeDesc"));
                        String startDate = "";
                        Date dStartDate = DateUtil.strToDate(KiteMapUtils.getString(feesMap, "startDate"));
                        startDate = DateUtil.format(dStartDate);
                        fee.setStartDate(startDate);
                        Date dEndDate = DateUtil.strToDate(KiteMapUtils.getString(feesMap, "endDate"));
                        String endDate = "";
                        endDate = DateUtil.format(dEndDate);
                        fee.setEndDate(endDate);
                        Date nowDate = new Date();
                        if (dEndDate.after(nowDate)) { //资费信息
                            resultfees.add(fee);
                        }
                        else { // 历史资费信息
                            resultHisfees.add(fee);
                        }
                    }
                }
            });
            if (KiteListUtils.isNotEmpty(resultfees)) {
                feeInfoVO.setFees(resultfees);
            }
            if (KiteListUtils.isNotEmpty(resultHisfees)) {
                hisFeeInfoVO.setFees(resultHisfees);

            }
        }
        return custViewVO;
    }

    private Map<String, Object> dealMemberUserDetailInfoInParams(QryGrpMemberDTO qryGrpMemberDTO) {
        String result;
        Map<String, Object> grpUserDetailMap;
        String pageNum = qryGrpMemberDTO.getPageNum();
        String pageSize = qryGrpMemberDTO.getPageSize();
        pageNum = KiteStringUtils.isNotEmpty(pageNum) ? pageNum : "1";
        pageSize = KiteStringUtils.isNotEmpty(pageSize) ? pageSize : "10";
        Map<String, Object> request = dealGroupUserDetailsParams(qryGrpMemberDTO, pageNum, pageSize);
        if (KiteStringUtils.isEqual(mode, "http")) {
            result = HttpsCallClient
                .postStringWithObject(LocalCallClientEnum.INF_COMMON_URL, request, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            result = infExchangeService.exchange(new JSONObject(request));
        }
        grpUserDetailMap = JSON.parseObject(result, Map.class);
        if (KiteMapUtils.isEmpty(grpUserDetailMap) || KiteMapUtils
            .isEmpty(KiteMapUtils.getMap(grpUserDetailMap, "data"))) {
            //            ErrorConsts.BUSI_COMMON_ERROR.throwOut("获取集团用户详情信息失败");
            return new HashMap<>();
        }
        return KiteMapUtils.getMap(grpUserDetailMap, "data");
    }

    /**
     * 组装查询集团用户详情信息入参
     *
     * @param qryGrpMemberDTO
     * @param pageNum
     * @param pageSize
     * @return
     */
    private Map<String, Object> dealGroupUserDetailsParams(QryGrpMemberDTO qryGrpMemberDTO, String pageNum,
        String pageSize) {
        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> uniBssBodyExt = new HashMap<>();
        Map<String, Object> req = new HashMap<>();
        Map<String, Object> memDiscntInfo = new HashMap<>();
        Map<String, Object> memDiscntInfoReq = new HashMap<>();
        Map<String, Object> memberListByMem = new HashMap<>();
        Map<String, Object> memberListByMemReq = new HashMap<>();
        req.put("SERIAL_NUMBER", qryGrpMemberDTO.getMemSerialNumber());
        req.put("USER_SOURCE", qryGrpMemberDTO.getMemSource());
        Map<String, String> tcpCount = new HashMap<>();
        tcpCount.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpCount.put("TRANS_ID", LocalTokenUtil.getTransId());
        req.put("TCP_CONT", tcpCount);
        List<Map<String, String>> qryTagInfosList = generateQryTagInfo();
        req.put("QRY_TAG_INFOS", qryTagInfosList);
        if (KiteStringUtils.isNotEmpty(qryGrpMemberDTO.getPrimaryUserId())) {
            memDiscntInfoReq.put("USER_IDA", Long.valueOf(qryGrpMemberDTO.getPrimaryUserId()));
        }
        if (KiteStringUtils.isNotEmpty(qryGrpMemberDTO.getMemUserId())) {
            memDiscntInfoReq.put("MEMBER_USER_ID", Long.valueOf(qryGrpMemberDTO.getMemUserId()));
        }
        memDiscntInfoReq.put("STATE_FLAG", "1");
        memberListByMemReq.put("MEM_EPARCHY_CODE", qryGrpMemberDTO.getMemEparchyCode());
        memberListByMemReq.put("CUR_PAGE", Integer.parseInt(pageNum));
        memberListByMemReq.put("PAGE_SIZE", Integer.parseInt(pageSize));
        memberListByMemReq.put("MEM_USER_ID", qryGrpMemberDTO.getMemUserId());
        memberListByMemReq.put("MEM_PROVINCE_CODE", qryGrpMemberDTO.getMemProvinceCode());
        memDiscntInfo.put("REQ", memDiscntInfoReq);
        memberListByMem.put("REQ", memberListByMemReq);
        uniBssBodyExt.put("MemDiscntInfo", memDiscntInfo);
        uniBssBodyExt.put("MemberListByMem", memberListByMem);
        uniBssBody.put("REQ", req);
        Map<String, Object> request = new HashMap<>();
        request.put("UNI_BSS_BODY_EXT", uniBssBodyExt);
        request.put("UNI_BSS_BODY", uniBssBody);
        request.put("OP_CODE", "qryJkAndCbUserDetailInfo_ZhuanDan");
        InfServiceHelper.adaptGray(request, req);
        return request;
    }

    private List generateQryTagInfo() {
        List tagInfoList = new ArrayList();
        String tagNames = "USER,USER_ITEM,PAYRELATION,USER_DISCNT,USER_DISCNT_ITEM,USER_CONTRACT,USER_CONTACT,USER_AGNET,USER_DEVELOP,USER_GOODS,USER_SERVICE,USER_SERVICE_ITEM";
        String[] keys = tagNames.split(",");
        for (int i = 0; i < keys.length; i++) {
            Map tagInfo = new HashMap();
            tagInfo.put("TRANSLATE_FLAG", "1");
            tagInfo.put("VALID_FLAG", "1");
            tagInfo.put("TAG_NAME", keys[i]);
            tagInfoList.add(tagInfo);
        }
        return tagInfoList;
    }

    /**
     * 查询用户详情
     *
     * @param inMap
     * @param userDetailTagNames TAG_NAME 详情见{@link UserDetailTagName}
     * @return
     */
    public Map<String, Object> queryUserDetailNew(Map<String, Object> inMap,
        List<UserDetailTagName> userDetailTagNames) {
        if (KiteListUtils.isEmpty(userDetailTagNames)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("TAG_NAME不可为空");
        }
        String provinceCode = KiteMapUtils.getString(inMap, "provinceCode");
        String eparchyCode = KiteMapUtils.getString(inMap, "eparchyCode");
        String staffCode = KiteMapUtils.getString(inMap, "staffCode");
        String accNum = KiteMapUtils.getString(inMap, "accNum");
        String userId = KiteMapUtils.getString(inMap, "userId");
        String staffId = KiteMapUtils.getString(inMap, "staffId");

        Map<String, Object> uniBssBodyMap = new HashMap<String, Object>();
        Map<String, Object> reqMap = new HashMap<String, Object>();
        // REQ
        reqMap.put("PROVINCE_CODE", provinceCode);
        reqMap.put("EPARCHY_CODE", eparchyCode);
        reqMap.put("STAFF_CODE", staffCode);
        reqMap.put("SERIAL_NUMBER", accNum);
        reqMap.put("USER_ID", userId);
        // PARA
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("PARA_ID", "");
        paraMap.put("PARA_VALUE", "");
        reqMap.put("PARA", paraMap);
        // CONTROL_NODE
        Map<String, Object> controlNodeMap = new HashMap<String, Object>();
        controlNodeMap.put("STAFF_ID", staffId);
        controlNodeMap.put("STAFF_CODE", staffCode);
        controlNodeMap.put("PROVINCE_CODE", provinceCode);
        controlNodeMap.put("EPARCHY_CODE", eparchyCode);
        controlNodeMap.put("CITY_CODE", "");
        controlNodeMap.put("VERSION", "1");
        reqMap.put("CONTROL_NODE", controlNodeMap);
        //tcp_cont
        Map<String, String> tcpContMap = new HashMap<String, String>();
        tcpContMap.put("APP_KEY", LocalInfConsts.APP_ID);
        tcpContMap.put("TRANS_ID", LocalTokenUtil.getTransId());
        reqMap.put("TCP_CONT", tcpContMap);
        uniBssBodyMap.put("REQ", reqMap);
        Map<String, Object> requestMap = LocalTokenUtil.getParamMap(uniBssBodyMap);
        requestMap.put("OP_CODE", "json_GEuserCenter_SalBusaGrpUserNewSerApi_qryGrpUserInfo");
        InfServiceHelper.adaptGray(requestMap, reqMap);
        //调接口查询用户详情信息
        Map rsp;
        if (KiteStringUtils.isEqual(mode, "http")) {
            rsp = HttpsCallClient.postObjMap(LocalCallClientEnum.INF_COMMON_URL.getCenterCode(),
                LocalCallClientEnum.INF_COMMON_URL.getServiceCode(), requestMap, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            String resultStr = infExchangeService.exchange(new JSONObject(requestMap));
            rsp = JSON.parseObject(resultStr, Map.class);
        }

        Map<String, Object> uniBssHead = (Map<String, Object>) rsp.get("UNI_BSS_HEAD");
        if (!KiteStringUtils.equals(LocalInfConsts.RESP_SUCCESS, KiteMapUtils.getString(uniBssHead, "RESP_CODE"))) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut(KiteMapUtils.getString(uniBssHead, "RESP_DESC"));
        }
        Map<String, Object> rspUniBssBodyMap = (Map<String, Object>) rsp.get("UNI_BSS_BODY");
        if (KiteMapUtils.isEmpty(rspUniBssBodyMap)) {
            ErrorConsts.INF_INVOKE_EXCEPTION.throwOut("接口返回报文缺少UNI_BSS_BODY节点信息!");
        }

        Map<String, Object> rspMap = (Map<String, Object>) rspUniBssBodyMap.get("RSP");
        if (!KiteStringUtils.equals("0000", KiteMapUtils.getString(rspMap, "RESP_CODE"))) {
            if (KiteStringUtils.equals("8888", KiteMapUtils.getString(rspMap, "RESP_CODE"))) {
                return null;
            }
        }
        return rspMap;
    }

}
